import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
var _excluded = ["userId", "authorityTypeCode", "authData", "authDataLineList"],
    _excluded2 = ["roleId", "authorityTypeCode", "authData", "authDataLineList"];

/**
 *  authorityDimensionService
 * @date: 2019-9-23
 */
import request from 'utils/request';
import { CPAAS_IAM } from 'utils/config';
import { getCurrentOrganizationId, parseParameters } from 'utils/utils';
/**
 * 查询
 * @export
 * @param {object} params - 查询参数

 */

export function queryUserAuthorityData(_x) {
  return _queryUserAuthorityData.apply(this, arguments);
}
/**
 * 查询
 * @export
 * @param {object} params - 查询参数

 */

function _queryUserAuthorityData() {
  _queryUserAuthorityData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var organizationId, param;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            organizationId = getCurrentOrganizationId();
            param = parseParameters(params);
            return _context.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(organizationId, "/users/").concat(param.userId, "/authority"), {
              method: 'GET',
              query: param
            }));

          case 3:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _queryUserAuthorityData.apply(this, arguments);
}

export function addUserAuthorityData(_x2) {
  return _addUserAuthorityData.apply(this, arguments);
}
/**
 * 查询
 * @export
 * @param {object} params - 查询参数

 */

function _addUserAuthorityData() {
  _addUserAuthorityData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    var userId, authorityTypeCode, userAuthority, userAuthorityLineList, others, organizationId;
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            userId = params.userId, authorityTypeCode = params.authorityTypeCode, userAuthority = params.authData, userAuthorityLineList = params.authDataLineList, others = _objectWithoutProperties(params, _excluded);
            organizationId = getCurrentOrganizationId();
            return _context2.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(organizationId, "/users/").concat(userId, "/authority"), {
              method: 'POST',
              query: {
                authorityTypeCode: authorityTypeCode
              },
              body: _objectSpread({
                userAuthorityLineList: userAuthorityLineList,
                userAuthority: userAuthority
              }, others)
            }));

          case 3:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _addUserAuthorityData.apply(this, arguments);
}

export function deleteUserAuthorityData(_x3) {
  return _deleteUserAuthorityData.apply(this, arguments);
}
/**
 * 查询
 * @export
 * @param {object} params - 查询参数

 */

function _deleteUserAuthorityData() {
  _deleteUserAuthorityData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    var userId, deleteRows, organizationId;
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            userId = params.userId, deleteRows = params.deleteRows;
            organizationId = getCurrentOrganizationId();
            return _context3.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(organizationId, "/users/").concat(userId, "/authority"), {
              method: 'DELETE',
              body: deleteRows
            }));

          case 3:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _deleteUserAuthorityData.apply(this, arguments);
}

export function queryRoleAuthorityData(_x4) {
  return _queryRoleAuthorityData.apply(this, arguments);
}
/**
 * 查询
 * @export
 * @param {object} params - 查询参数

 */

function _queryRoleAuthorityData() {
  _queryRoleAuthorityData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    var organizationId, param;
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            organizationId = getCurrentOrganizationId();
            param = parseParameters(params);
            return _context4.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(organizationId, "/role/").concat(param.roleId, "/authority"), {
              method: 'GET',
              query: param
            }));

          case 3:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _queryRoleAuthorityData.apply(this, arguments);
}

export function addRoleAuthorityData(_x5) {
  return _addRoleAuthorityData.apply(this, arguments);
}
/**
 * 查询
 * @export
 * @param {object} params - 查询参数

 */

function _addRoleAuthorityData() {
  _addRoleAuthorityData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    var roleId, authorityTypeCode, roleAuthData, roleAuthDataLineList, others, organizationId;
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            roleId = params.roleId, authorityTypeCode = params.authorityTypeCode, roleAuthData = params.authData, roleAuthDataLineList = params.authDataLineList, others = _objectWithoutProperties(params, _excluded2);
            organizationId = getCurrentOrganizationId();
            return _context5.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(organizationId, "/role/").concat(roleId, "/authority"), {
              method: 'POST',
              query: {
                authorityTypeCode: authorityTypeCode
              },
              body: _objectSpread({
                roleAuthData: roleAuthData,
                roleAuthDataLineList: roleAuthDataLineList,
                roleId: roleId,
                authorityTypeCode: authorityTypeCode
              }, others)
            }));

          case 3:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _addRoleAuthorityData.apply(this, arguments);
}

export function deleteRoleAuthorityData(_x6) {
  return _deleteRoleAuthorityData.apply(this, arguments);
}

function _deleteRoleAuthorityData() {
  _deleteRoleAuthorityData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    var roleId, deleteRows, organizationId;
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            roleId = params.roleId, deleteRows = params.deleteRows;
            organizationId = getCurrentOrganizationId();
            return _context6.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(organizationId, "/role/").concat(roleId, "/authority"), {
              method: 'DELETE',
              body: deleteRows
            }));

          case 3:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _deleteRoleAuthorityData.apply(this, arguments);
}